var _n85;
var cc__extends = __extends;
var cc__decorate = __decorate;
var cc__importDefault = __importDefault;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $1$EventManager = require("EventManager");
var s = cc__importDefault($1$EventManager);
var $1$yyComponent = require("yyComponent");
var c = cc__importDefault($1$yyComponent);
var $GameEventType = require("GameEventType");
var $1$Ipha_tool = require("Ipha_tool");
var u = cc__importDefault($1$Ipha_tool);
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_xinshouyindao = function (t) {
  function _ctor() {
    const instance = (t !== null) ? t.apply(this, arguments) : this; // 调用 t，或者使用当前上下文

    // 初始化属性
    instance.yuanquan = null;
    instance.yindaoLabel = null;
    instance.str = [
      "点击选择",
      "同类型放在一起",
      "满足数量后合并为下一个等级",
      "即将下落的牌",
      "点击下落",
      "点击选择",
      "同类型放在一起",
      "继续合成",
      "这是本关的合成目标",
      "获得更多的牌"
    ];
    instance.fx = [1, 1, 1, 2, 1, 1, 1, 1, 2, 1]; // fx 数组
    instance.nodeArr = []; // nodeArr 数组
    instance.tdata = []; // tdata 数组
    instance.zhuanhuang = true; // zhuanhuang
    instance.pianyiY = 0; // pianyiY
    instance.nowindex = 0; // nowindex
    instance.chumo = 8; // chumo
    instance.chumoArr = []; // chumoArr 数组
    instance.yindaoIndex = 0; // yindaoIndex

    return instance; // 返回对象
  }
  cc__extends(_ctor, t);
  _ctor.prototype.start = function () {
    const instance = this; // 更明确的实例引用
    this.yindaoLabel.string = this.str[this.nowindex]; // 设置指引标签的文本
    this.gengxinweizhi(); // 更新位置

    // 注册事件监听
    this.on($GameEventType.EventType.DirectorEvent.xinshouyindao, this.nextyindao, this);

    // 注册触摸事件
    const bgNode = this.node.getChildByName("maskNode").getChildByName("bg");
    bgNode.on(cc.Node.EventType.TOUCH_END, () => {
      const { nowindex, chumo, chumoArr } = instance; // 解构赋值提高可读性
      if (nowindex === chumo || chumo === -999 || chumoArr.includes(nowindex)) {
        instance.nextyindao(); // 确定条件后调用 nextyindao
      }
    }, this);

  };
  _ctor.prototype.nextyindao = function () {
    const instance = this; // 更明确的实例引用
    if (this.node && this.node.parent) { // 确保节点存在且有父节点
      let delay = 0; // 使用 let 声明延迟
      if (this.nowindex + 1 === this.chumo) { // 检查当前索引加一是否等于 chumo
        delay = 0.5; // 设置延迟为 0.5 秒
        this.node.opacity = 0; // 将节点的透明度设置为 0
      }
      // 调度一次性函数
      this.scheduleOnce(() => {
        instance.node.opacity = 255; // 将透明度设置为 255
        instance.nowindex++; // 当前索引增加

        if (instance.nowindex >= instance.str.length && instance.node && instance.node.parent) { // 检查索引是否超过字符串数组长度
          instance.node.parent = null; // 将节点从父节点中移除
          return s.default.emit($GameEventType.EventType.DirectorEvent.xinshouyindaoEnd); // 发送事件
        }
        // 更新指引标签的文本和位置
        instance.yindaoLabel.string = instance.str[instance.nowindex];
        instance.gengxinweizhi(); // 更新位置
      }, delay); // 使用延迟
    }
  };
  _ctor.prototype.gengxinweizhi = function () {
    const targetPosition = u.default.pos.rootPosToTargetNodeSpace(this.nodeArr[this.nowindex], this.node); // 将位置转换
    this.yuanquan.position = targetPosition; // 设置圆圈位置

    // 设置锚点和尺寸
    const currentNode = this.nodeArr[this.nowindex];
    this.yuanquan.anchorX = currentNode.anchorX;
    this.yuanquan.anchorY = currentNode.anchorY;
    this.yuanquan.width = currentNode.width;
    this.yuanquan.height = currentNode.height;
    this.yuanquan.scale = currentNode.scale;

    // 如果有附加数据，则更新属性
    if (this.tdata[this.nowindex]) {
      const additionalData = this.tdata[this.nowindex];
      this.yuanquan.anchorX = additionalData.anchorX;
      this.yuanquan.anchorY = additionalData.anchorY;
      this.yuanquan.width = additionalData.width;
      this.yuanquan.height = additionalData.height;
      this.yuanquan.x += additionalData.x_;
      this.yuanquan.y += additionalData.y_;
    }

    // 根据 fx 值调整 yindaoLabel 位置
    const parentNode = this.yindaoLabel.node.parent;
    let offsetY = 0;

    switch (this.fx[this.nowindex]) {
      case 1:
        offsetY = this.yuanquan.y + 150;
        parentNode.children[0].scaleY = -1;
        break;
      case 2:
        offsetY = this.yuanquan.y - 150 - this.pianyiY;
        parentNode.children[0].scaleY = 1;
        if (this.nowindex === 7) { // 使用严格比较
          offsetY = this.yuanquan.y - 150;
        }
        break;
      case 3:
        parentNode.x = this.yuanquan.x - 100;
        parentNode.y = this.yuanquan.y;
        return; // 提前返回
      default:
        parentNode.x = this.yuanquan.x + 100;
        parentNode.y = this.yuanquan.y;
        return; // 提前返回
    }

    // 设置 yindaoLabel 位置
    parentNode.y = offsetY;

    if (this.yuanquan.x > 0) {
      parentNode.children[0].scaleX = -1;
      parentNode.x = this.yuanquan.x - 150;
    } else {
      parentNode.children[0].scaleX = 1;
      parentNode.x = this.yuanquan.x + 150;
    }
  };
  cc__decorate([ccp_property(cc.Node)], _ctor.prototype, "yuanquan", undefined);
  cc__decorate([ccp_property(cc.Label)], _ctor.prototype, "yindaoLabel", undefined);
  return cc__decorate([ccp_ccclass], _ctor);
}(c.default);
exports.default = def_xinshouyindao;